﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Abp.AutoMapper;
using Abp.Modules;
using Abp.Reflection.Extensions;
using GCT.Foundation.Authorization;
using GCT.Foundation.CacheState.Authorization;
using GCT.Foundation.CustomDtoAutoMapper;
using GCT.Foundation.ListViews.Mapper;
using GCT.Foundation.PageFilters.Mapper;
using GCT.Foundation.UserLogs.Authorzation;
using GCT.Foundation.UserLogs.Mapper;

namespace GCT.Foundation
{
    [DependsOn(
        typeof(GCTSharedApplicationModule),
        typeof(FoundationTemplateCoreModule)
    )]
    public class FoundationTemplateApplicationModule : AbpModule
    {
        public override void PreInitialize()
        {
            // 配置Dto映射
            this.ConfigureAutoMapper();

            // 注册权限 AuthorizationProvider

            // 示例
            // Configuration.Authorization.Providers.Add<xxxAuthorizationProvider>();
            Configuration.Authorization.Providers.Add<TemplateAuthorizationProvider>();
            //Configuration.Authorization.Providers.Add<MenuAuthorizationProvider>();
            Configuration.Authorization.Providers.Add<LoginLogsAuthorizationProvider>();

            // 缓存监控权限
            Configuration.Authorization.Providers.Add<CacheStateAuthorizationProvider>();
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(this.GetType().GetAssembly());
        }

        public override void PostInitialize()
        {
        }

        private void ConfigureAutoMapper()
        {
            Configuration.Modules.AbpAutoMapper().Configurators.Add(configuration =>
            {
                LoginLogsDtoMapper.CreateMappings(configuration);
            });
        }
    }
}
